﻿using System.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyInterfaces;
using MyServiceClasses;

namespace TestProject1
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        private IUnityContainer unityContainer;
        public UnitTest1()
        {
            unityContainer = new UnityContainer();
            UnityConfigurationSection section =
                (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Containers["myContainer"].Configure(unityContainer);
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void Test_MyService_SayHello()
        {
            //Just testing the implemented interface methods..
            IMyService service = new MyService();
            Assert.AreEqual("Hello, you wrote : Hello", service.SayHello("Hello"));
        }

        [TestMethod]
        public void Test_MyService_IsThisRight()
        {
            //Just testing the implemented interface methods..
            IMyService service = new MyService();
            Assert.AreEqual(true, service.IsThisRight("Right"));
        }

        [TestMethod]
        public void Test_Unity_MyService_SayHello()
        {
            IMyService service = unityContainer.Resolve<IMyService>();
            Assert.AreEqual("Hello, you wrote : Hello", service.SayHello("Hello"));
        }
    }
}
